# Define here the models for your scraped items
#
# See documentation in:
# https://docs.scrapy.org/en/latest/topics/items.html

import scrapy


class BookItem(scrapy.Item):
    # define the fields for your item here like:
    # name = scrapy.Field()
    pass

#案例
class BooksSpiders(scrapy.Spider):
    name="books"#爬虫唯一标识
    start_urls=["https://books.toscrape.com"]#起始url

    def parse(self, response, **kwargs):
        for book in response.css('article.product_pud'):
            name=book.xpath('./h3/a/@title').extract_first()
            price=book.css('p.price_color::text').extract_first()
            yield('name':name,'price':price,)

            next_url=response.css('ul.pager li.next a::attr(href)').extract_first()
            if next_url:
                next_url=response.urljoin(next_url)
                yield scrapy.Request(next_url,callback=self.parse())



